package sz.szsmk.citizencard.ui.dialogs

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.DialogFragment
import sz.szsmk.citizencard.R
import sz.szsmk.citizencard.databinding.DialogPrePermissionBinding

/**
 *  @author : hyt
 *  @date : 2021/11/24
 *  @description :
 */
class PrePermissionDialog(var block:()->Unit) :DialogFragment() {


    companion object{
        fun newInstance(block:()->Unit):PrePermissionDialog{
            return PrePermissionDialog(block)
        }
    }
    lateinit var mViewBinding :DialogPrePermissionBinding

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        dialog?.requestWindowFeature(Window.FEATURE_NO_TITLE)

        dialog?.window?.setBackgroundDrawableResource(android.R.color.transparent)

        mViewBinding = DataBindingUtil.inflate(inflater, R.layout.dialog_pre_permission, container, false)

        return mViewBinding.root
    }

    override fun onStart() {
        super.onStart()

        var attribute = dialog?.window?.attributes
        attribute?.width = resources.displayMetrics.widthPixels
        dialog?.window?.attributes = attribute
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        //app头像。 休闲年卡头像。 h5办理休闲年卡处
        mViewBinding.policyText.text = getString(R.string.camera_permission)
        mViewBinding.policyRefuse.setOnClickListener { this.dismiss() }

        mViewBinding.policyAgree.setOnClickListener {
            block()
            this.dismiss()
        }


    }


}